<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ModuleAcl
 *
 * @author neozilon
 */
class Nosql_Acl_ModuleAcl extends Zend_Acl {
    const ROLE_GUEST = 'GUEST';
    const ROLE_USER = 'USER';
    const ROLE_AUTHOR = 'AUTHOR';
    const ROLE_ADMIN = 'ADMIN';

    /**
     * @var NoSql_Acl_ModuleAcl acl
     */
    private static $acl;

    public function __construct() {

        //added all the roles
        $this->addRole(new Zend_Acl_Role(self::ROLE_GUEST));

        $this->addRole(new Zend_Acl_Role(self::ROLE_USER), self::ROLE_GUEST);

        $this->addRole(new Zend_Acl_Role(self::ROLE_AUTHOR), self::ROLE_GUEST);

        $this->addRole(new Zend_Acl_Role(self::ROLE_ADMIN), self::ROLE_AUTHOR);

        // now we add the module resources
        $this->addResource(new Zend_Acl_Resource('default'));
        $this->addResource(new Zend_Acl_Resource('user'));
        $this->addResource(new Zend_Acl_Resource('admin'));

        /**
         * Default controllers
         */
        $this->addResource(new Zend_Acl_Resource('default' . 'error'));
        $this->allow(self::ROLE_GUEST, 'default' . 'error');

        /**
         * Admin controllers Resources and permissions
         */
        $this->addResource(new Zend_Acl_Resource('admin' . 'users'));
        $this->allow(self::ROLE_ADMIN, 'admin' . 'users');

        $this->addResource(new Zend_Acl_Resource('admin' . 'login'));
        $this->allow(self::ROLE_GUEST, 'admin' . 'login');

        $this->addResource(new Zend_Acl_Resource('admin' . 'index'));
        $this->allow(self::ROLE_ADMIN, 'admin' . 'index');
        
        $this->addResource(new Zend_Acl_Resource('admin' . 'category'));
        $this->allow(self::ROLE_ADMIN, 'admin' . 'category');

        $this->addResource(new Zend_Acl_Resource('admin' . 'post'));
        $this->allow(self::ROLE_ADMIN, 'admin' . 'post');

        $this->addResource(new Zend_Acl_Resource('admin' . 'test'));
        $this->allow(self::ROLE_ADMIN, 'admin' . 'test');

        /**
         * Permissions for the default 
         */
        $defaultModule = 'default';
         $this->addResource(new Zend_Acl_Resource($defaultModule . 'index'));
         $this->allow(self::ROLE_GUEST, 'default' . 'index');

          $this->addResource(new Zend_Acl_Resource($defaultModule . 'articulo'));
         $this->allow(self::ROLE_GUEST, 'default' . 'articulo');

          $this->addResource(new Zend_Acl_Resource($defaultModule . 'categorias'));
         $this->allow(self::ROLE_GUEST, 'default' . 'categorias');

         $this->addResource(new Zend_Acl_Resource($defaultModule . 'categoria'));
         $this->allow(self::ROLE_GUEST, 'default' . 'categoria');

         $this->addResource(new Zend_Acl_Resource($defaultModule . 'tests'));
         $this->allow(self::ROLE_GUEST, 'default' . 'tests');
        

        //now we assign permissions to the roles
        $this->allow(self::ROLE_GUEST, 'default');

        $this->allow(self::ROLE_USER, 'default');

        $this->allow(self::ROLE_AUTHOR, 'admin');
    }

    /**
     *
     * @return Nosql_Acl_ModuleAcl
     */
    public static function getInstance() {
        if (self::$acl == null) {
            self::$acl = new Nosql_Acl_ModuleAcl();
        }

        return self::$acl;
    }

}